﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace subtitle_modifier
{
    class GeneralFunctions
    {
        public static int WordCount(string Sentence)
        {
            char[] delimiters = new char[] { ',', '.', '[', ']', '<', '>', '(', ')', '{', '}', ' ', ';', ':', '"', '\\', '/', '+', '*', '!', '@', '#', '$', '%', '^', '&', '=' };
            return Sentence.Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Length;
        }

        public static double getStandardDeviation(List<double> doubleList)
        {
            double average = doubleList.Average();
            double sumOfDerivation = 0;
            foreach (double value in doubleList)
            {
                sumOfDerivation += (value) * (value);
            }
            double sumOfDerivationAverage = sumOfDerivation / doubleList.Count;
            return Math.Sqrt(sumOfDerivationAverage - (average * average));
        }

        public static double SimilarSentences(string FirstSen, string SecondSen)
        {
            double Quality = 0;

            if (FirstSen.Equals(SecondSen))
            {
                Quality = 100;
            }
            else
            {
                char[] delimiters = new char[] { ',', '.', '[', ']', '<', '>', '(', ')', '{', '}', ' ', ';', ':', '"', '\\', '/', '+', '*', '!', '@', '#', '$', '%', '^', '&', '=' };
                string[] FirstSenWords = FirstSen.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                string[] SecondSenWords = SecondSen.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                int Count = 0;
                foreach (string word in FirstSenWords)
                {
                    if (SecondSenWords.Contains(word))
                    {
                        Count++;
                    }
                }
                try
                {
                    Quality = ((100 * Count) / ((FirstSenWords.Length + SecondSenWords.Length) / 2));
                }
                catch (Exception) { }

            }
            return Quality;
        }
    }
}
